//
//  OEShopHeaderViewController.m
//  OneEightyNine
//
//  Created by Mac on 2019/3/7.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEShopHeaderViewController.h"
#import "OEShopDetailViewController.h"
@interface OEShopHeaderViewController ()

@end

@implementation OEShopHeaderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self configSubView];
    [self vhl_setStatusBarStyle:UIStatusBarStyleLightContent];
    [OEHomeDataController sendGetShopDetailRequest:self.model.supplier_id handle:^(BOOL success, NSString *errorString, NSDictionary *resp) {
        if (success) {
            self.model = [OEShopEasyModel mj_objectWithKeyValues:resp];
        }
        [self configSubView];
    }];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [OEHomeDataController sendGetShopDetailRequest:self.model.supplier_id handle:^(BOOL success, NSString *errorString, NSDictionary *resp) {
        if (success) {
            self.model = [OEShopEasyModel mj_objectWithKeyValues:resp];
        }
    }];
}
#pragma mark --subView
- (void)configSubView{
    [self vhl_setNavBarBackgroundAlpha:0];
    __weak typeof(self) weakSelf =  self;

    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 220)];
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.model.supplier_logo]];
    [self.view addSubview:imageView];

    [self.view bringSubviewToFront:self.tableView];
    self.tableView.backgroundColor = UIColor.clearColor;
    self.view.backgroundColor = OE_GrayColor;
    
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(10, 60, UIScreenWidth - 20, 100)];
    whiteView.layer.cornerRadius = 10;
    whiteView.clipsToBounds = YES;
    whiteView.backgroundColor = UIColor.whiteColor;
    [footer addSubview:whiteView];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 20, whiteView.width  - 60, 44)
                                                text:self.model.supplier_name
                                           textColor:FirstTextColor
                                                font:17
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    [whiteView addSubview:titleLable];
    
    
    UIImageView * iconimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 50, 50)];
    [iconimageView sd_setImageWithURL:[NSURL URLWithString:self.model.supplier_logo]];
    iconimageView.layer.cornerRadius = 25;
    iconimageView.clipsToBounds = YES;
    iconimageView.right = whiteView.width - 10;
    [whiteView addSubview:iconimageView];
    titleLable.centerY = iconimageView.centerY;
    
   STButton * allButton = [[STButton alloc] initWithFrame:CGRectMake(0, iconimageView.bottom  +10, titleLable.width / 3, 40)
                                               title:[NSString stringWithFormat:@"ALL %@",self.model.share_count]
                                          titleColor:OE_LIMITE_COLOR
                                           titleFont:15
                                        cornerRadius:0
                                     backgroundColor:UIColor.whiteColor
                                     backgroundImage:nil
                                               image:nil];
    allButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [allButton st_showRightLine:20];
    [whiteView addSubview:allButton];
    
    STButton * borrowButton = [[STButton alloc] initWithFrame:CGRectMake(allButton.right, iconimageView.bottom  +10, titleLable.width / 3, 40)
                                                     title:[NSString stringWithFormat:@"BORROW %@",self.model.borrow_count]
                                                titleColor:OE_LIMITE_COLOR
                                                 titleFont:15
                                              cornerRadius:0
                                           backgroundColor:UIColor.whiteColor
                                           backgroundImage:nil
                                                     image:nil];
    borrowButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [borrowButton st_showRightLine:20];
    [whiteView addSubview:borrowButton];
    
    STButton * returnButton = [[STButton alloc] initWithFrame:CGRectMake(borrowButton.right, iconimageView.bottom  +10, titleLable.width / 3, 40)
                                                        title:[NSString stringWithFormat:@"Retun %@",self.model.return_count]
                                                   titleColor:OE_LIMITE_COLOR
                                                    titleFont:15
                                                 cornerRadius:0
                                              backgroundColor:UIColor.whiteColor
                                              backgroundImage:nil
                                                        image:nil];
    returnButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [whiteView addSubview:returnButton];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0,returnButton.bottom, whiteView.width, 0.5)];
    line.backgroundColor = TM_lineColor;
    [whiteView addSubview:line];
    
    STButton * timeButton = [[STButton alloc] initWithFrame:CGRectMake(titleLable.left, line.bottom, whiteView.width, 44)
                                                title:[NSString stringWithFormat:@"%@-%@",_model.start_time,_model.end_time]
                                           titleColor:SecendTextColor
                                            titleFont:14
                                         cornerRadius:0
                                      backgroundColor:nil
                                      backgroundImage:nil
                                                image:[UIImage imageNamed:@"24×24时间"]];
    [whiteView addSubview:timeButton];
    
    
    
    STButton * addButton = [[STButton alloc] initWithFrame:CGRectMake(titleLable.left, timeButton.bottom, whiteView.width - 100, 50)
                                               title:self.model.address
                                          titleColor:SecendTextColor
                                           titleFont:13
                                        cornerRadius:0
                                     backgroundColor:UIColor.whiteColor
                                     backgroundImage:nil
                                               image:[UIImage imageNamed:@"24×30地址"]];
    [whiteView addSubview:addButton];
    addButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    timeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    [addButton st_showRightLine:30];
    
    STMenuControl * menu = [[STMenuControl alloc] initWithFrame:CGRectMake(0,0, 100, 50) imageName:@"28×28导航" title:self.model.distance titleColor:FirstTextColor];
    menu.centerY = addButton.centerY;;
    [whiteView addSubview:menu];
    menu.imageButton.frame = CGRectMake(0, 0, 30, 30);
    menu.imageButton.centerX = 50;
    menu.titleLable.top = 30;
    menu.titleLable.height = 20;
    menu.right = whiteView.width;

    STButton * phoneButton = [[STButton alloc] initWithFrame:CGRectMake(titleLable.left, addButton.bottom, whiteView.width - 100, 44)
                                                     title:self.model.mobile
                                                titleColor:SecendTextColor
                                                 titleFont:13
                                              cornerRadius:0
                                           backgroundColor:UIColor.whiteColor
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"30×30电话"]];
    [phoneButton setClicAction:^(UIButton *sender) {
        NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",weakSelf.model.mobile];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; 

    }];
    [whiteView addSubview:phoneButton];
    phoneButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    
    whiteView.height = phoneButton.bottom;
    footer.height = whiteView.bottom;
    self.tableView.tableFooterView = footer;
    
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, TMUtils.tabBarTop, UIScreenWidth - 60 , 44)
                                                        title:@"Scan Goods"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:22
                                              backgroundColor:OE_LIMITE_COLOR
                                              backgroundImage:nil
                                                        image:nil];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [confimButton setClicAction:^(UIButton *sender) {
        OEShopDetailViewController * vc = OEShopDetailViewController.new;
        vc.model = weakSelf.model;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [self.view addSubview:confimButton];
}

@end
